package org.bee.service;

import org.bee.mappers.RoleElementMapper;
import org.bee.model.RoleElement;
import org.bee.model.RoleElementExample;
import org.springframework.stereotype.Service;

@Service
public class RoleElementService {

    private final RoleElementMapper roleElementMapper;

    public RoleElementService(RoleElementMapper roleElementMapper) {
        this.roleElementMapper = roleElementMapper;
    }

    public void deleteByRoleId(String roleId) {
        RoleElementExample example = new RoleElementExample();
        RoleElementExample.Criteria criteria = example.createCriteria();
        criteria.andRoleIdEqualTo(roleId);
        roleElementMapper.deleteByExample(example);
    }

    public void saveRoleElement(String id, String elementId) {
        RoleElement roleElement = new RoleElement();
        roleElement.setRoleId(id);
        roleElement.setElementId(elementId);
        roleElementMapper.insert(roleElement);
    }
}
